<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/22 0022
 * Time: 上午 11:57
 */
namespace app\common\service;

use app\common\BaseHelper;

/*
 * 打印排版类
 * 目前只支持飞鹅WIFI无线打印机(58mm和80mm)
 */
class PrinterTemplate{
    private $goodsData;
    private $name;
    private $value;
    private $printtype;
    private $order;
    public function __construct($goodsData,$name,$value,$printtype,$order)
    {
        $this->goodsData = $goodsData;
        $this->name = $name;
        $this->value = $value;
        $this->printtype = $printtype;
        $this->order = $order;
    }

    private function getSerialNumber($serialNumber){
        return substr($serialNumber,-4);

    }

    public function printtemp(){
        if(!empty($this->value['type'])){
            $type = explode(',', $this->value['type']);
        }else{
            $type = '';
        }
        $html = '';
        $str = '';
        if(!empty($this->goodsData)){
            if($this->printtype == 1){
                //58mm打印机
                if(isset($this->value['isdadaprint']) && $this->value['isdadaprint'] == 'yes'){
                    //达达配送单
                    $total = 0;
                    $str = '';
                    $str .= '<CB>'.$this->name.'</CB><BR>';
                    $str .= '<C>'.$this->value['xiaopiaoname'].'</C><BR>';  //帐单名称
                    if($this->order['status'] != 1){
                        $str .= '<CB>（已支付）</CB><BR>';
                    }else{
                        $str .= '<CB>（未支付）</CB><BR>';
                    }
                    $str .= '订单号：'.$this->order['orderNO'].'<BR>';
                    $str .= '支付时间：'.$this->order['payDate'].'<BR>';
                    /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';
                    $str .= '操作人：'.$this->model->operator.'<BR>';*/
                    $str .= '--------------------------------<BR>';
                    $str .= '名称　　　　　  单价  数量 金额<BR>';
                    $str .= '--------------------------------<BR>';
                    foreach ($this->goodsData as $goods)
                    {
                        $len = strlen($goods['name'])/3*2;  //12
                        $str .= $goods['name'].str_pad('',14 - $len,' ').' '.str_pad($goods['price']/100, 5, ' ').'   '.$goods['quantity'].'  '.sprintf('%.2f', $goods['price']/100 * $goods['quantity']).'<BR>';
                        $total += $goods['price'] * $goods['quantity'];
                    }
                    $str .= '--------------------------------<BR>';
                    $discount = ($this->order['oldSaleMoney'] + $this->order['oldMemberPrice'])/100;
                    $str .= '配送费：'. str_pad(sprintf('%.2f', $this->order['freight']/100), 22, ' ', STR_PAD_LEFT).'<BR>';
                    $str .= '包装费：'. str_pad(sprintf('%.2f', $this->order['packingfee']/100), 22, ' ', STR_PAD_LEFT).'<BR>';
                    $str .= '--------------------------------<BR>';
                    $str .= '原价：'. str_pad(sprintf('%.2f', $this->order['total']/100 + $discount), 24, ' ', STR_PAD_LEFT).'<BR>';
                    $str .= '优惠：'. str_pad(sprintf('%.2f', $discount/100), 24, ' ', STR_PAD_LEFT).'<BR>';
                    $str .= '<B>实付：'. str_pad(sprintf('%.2f', $this->order['total']/100), 10, ' ', STR_PAD_LEFT).'</B><BR>';
                    $str .= '--------------------------------<BR>';
                    $str .= '<BR>';
                    $str .= '<B>地址：'.$this->order['deliverAddress'].'</B><BR><BR>';
                    $str .= '<B>'.$this->order['userPhone'].'</B><BR>';
                    $str .= '--------------------------------<BR>';
                    $str .= '备注：'.$this->order['content'].'<BR>';
                    $str .= '<BR>';
                    /*$str .= '<C>提前扫码关注，优惠买单</C><BR>';
                    $str .= '<QR>http://www.1miaodao.cn</QR>';*/
                    $str .= '<PLUGIN>';
                    $str .= '<BR>';
                    $html .= $str;
                }else{
                    if ($this->value['name'] == '对帐单'){
                        if ($this->value['mode'] == '一个商品一单'){
                            foreach ($this->goodsData as $goods)
                            {
                                if (empty($type) || in_array($goods['categoryId'], $type))
                                {
                                    $total = 0;
                                    $str = '';
                                    if ($total > 0)
                                        $str .= '<CUT>';
                                    $str .= '<CB>'.$this->name.'</CB><BR>';
                                    $str .= '<C>'.$this->value['name'].'</C><BR>';  //帐单名称
                                    /*$str .= '<CB>排队号：'.$this->getSerialNumber($this->order['orderNO']).'</CB><BR>';*/
                                    $str .= '订单号：' . $this->order['orderNO'] . '<BR>';
                                    $str .= '时间：'.date('Y-m-d H:i').'<BR>';
                                    /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';*/
                                    /*$str .= '操作人：'.$this->model->operator.'<BR>';*/
                                    $str .= '--------------------------------<BR>';
                                    $str .= '名称　　　　　  单价  数量 金额<BR>';
                                    $str .= '--------------------------------<BR>';

                                    $len = strlen($goods['name'])/3*2;  //12
                                    $str .= $goods['name'].str_pad('',14 - $len,' ').' '.str_pad($goods['price'], 5, ' ').'   '.$goods['quantity'].'  '.sprintf('%.2f', $goods['price'] * $goods['quantity']).'<BR>';
                                    $total += $goods['price'] * $goods['quantity'];

                                    $str .= '--------------------------------<BR>';
                                    $str .= '合计：'. str_pad(sprintf('%.2f', $total), 24, ' ', STR_PAD_LEFT).'<BR>';
                                    $str .= '--------------------------------<BR>';
                                    $str .= '备注：'.$this->order['content'].'<BR>';
                                    $str .= '<BR>';
                                    $str .= '<C>扫一扫提前线上点餐，优惠买单</C><BR>';
                                    $str .= '<PLUGIN>';
                                    $str .= '<BR>';
                                    $html .= $str;
                                }
                            }
                        }else{
                            $total = 0;
                            $str = '';
                            $str .= '<CB>'.$this->name.'</CB><BR>';
                            $str .= '<C>'.$this->value['name'].'</C><BR>';  //帐单名称
                            /*$str .= '<CB>排队号：'.$this->getSerialNumber($this->result['serialNumber']).'</CB><BR>';*/
                            $str .= '订单号：' . $this->order['orderNO'] . '<BR>';
                            $str .= '时间：'.date('Y-m-d H:i').'<BR>';
                            /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';*/
                            /*$str .= '操作人：'.$this->model->operator.'<BR>';*/
                            $str .= '--------------------------------<BR>';
                            $str .= '名称　　　　　  单价  数量 金额<BR>';
                            $str .= '--------------------------------<BR>';
                            foreach ($this->goodsData as $goods)
                            {
                                if (empty($type) || in_array($goods['categoryId'], $type))
                                {
                                    $len = strlen($goods['name']) / 3 * 2;  //12
                                    $str .= $goods['name'] . str_pad('', 14 - $len, ' ') . ' ' . str_pad(sprintf('%.2f', $goods['price']/100), 5, ' ') . '   ' . $goods['quantity'] . '  ' . sprintf('%.2f', $goods['price']/100 * $goods['quantity']) . '<BR>';
                                    $total += $goods['price']/100 * $goods['quantity'];
                                }
                            }
                            $str .= '--------------------------------<BR>';
                            $str .= '合计：'. str_pad(sprintf('%.2f', $total), 24, ' ', STR_PAD_LEFT).'<BR>';
                            $str .= '--------------------------------<BR>';
                            $str .= '备注：'.$this->order['content'].'<BR>';
                            $str .= '<BR>';
                            $str .= '<C>扫一扫提前线上点餐，优惠买单</C><BR>';
                            $str .= '<PLUGIN>';
                            $str .= '<BR>';
                            if ($total > 0)
                                $html .= $str;
                        }
                    }elseif ($this->value['name'] == '出品单'){
                        if($this->value['mode'] == '一个商品一单'){
                            $num = 0;
                            foreach ($this->goodsData as $goods)
                            {
                                if (empty($type) || in_array($goods['categoryId'], $type))
                                {
                                    $str = '';
                                    if ($num > 0)
                                        $str .= '<CUT>';
                                    $str .= '<CB>' . $this->name . '</CB><BR>';
                                    $str .= '<C>' . $this->value['name'] . '</C><BR>';  //帐单名称
                                    /*$str .= '<CB>排队号：'.$this->getSerialNumber($this->result['serialNumber']).'</CB><BR>';*/
                                    $str .= '订单号：' . $this->order['orderNO'] . '<BR>';
                                    $str .= '时间：' . date('Y-m-d H:i') . '<BR>';
                                    /*$str .= '餐桌：' . $this->result['tableName'] . '　　　　　 人数：' . $this->result['number'] . '<BR>';*/
                                    /*$str .= '操作人：'.$this->model->operator.'<BR>';*/
                                    $str .= '--------------------------------<BR>';
                                    $str .= '名称　　　　　        数量     <BR>';
                                    $str .= '--------------------------------<BR>';
                                    $name = BaseHelper::printCaiName($goods['name'],1);
                                    $str .= $name .'   '. '<B>'.$goods['quantity'] . '份</B>  <BR>';
                                    $str .= '--------------------------------<BR>';
                                    $str .= '备注：' . $this->order['content'] . '<BR>';
                                    $str .= '<BR>';
                                    $str .= '<PLUGIN>';
                                    $str .= '<BR>';
                                    $html .= $str;
                                    $num++;
                                }
                            }
                        }elseif ($this->value['mode'] == '分类打印'){
                            $num = 0;
                            $newgoodsData = array();
                            foreach ($this->goodsData as $k=>$v){
                                $newgoodsData[$v['caiping']][] = $v;
                            }
                            foreach ($newgoodsData as $k=>$goods){
                                $total = 0;
                                $str = '';
                                if($num>0)
                                    $str .= '<CUT>';
                                $str .= '<CB>'.$this->name.'</CB><BR>';
                                $str .= '<C>'.$this->value['name'].'</C><BR>';  //帐单名称
                                /*$str .= '<CB>排队号：'.$this->getSerialNumber($this->result['serialNumber']).'</CB><BR>';*/
                                $str .= '订单号：'.$this->order['orderNO'].'<BR>';
                                $str .= '时间：'.date('Y-m-d H:i').'<BR>';
                                /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';
                                $str .= '操作人：'.$this->model->operator.'<BR>';*/
                                $str .= '<B>品类：'.$k.'</B><BR>';
                                $str .= '--------------------------------<BR>';
                                $str .= '名称　　　　　             数量<BR>';
                                $str .= '--------------------------------<BR>';
                                foreach ($goods as $good){
                                    if (empty($type) || in_array($good['categoryId'], $type))
                                    {
                                        $name = BaseHelper::printCaiName($good['name'],1);
                                        $str .= $name .'   '. '<B>'.$good['quantity'] . '份</B>  <BR>';
                                        $total += $good['price'] * $good['quantity'];
                                    }
                                }
                                $str .= '--------------------------------<BR>';
                                $str .= '备注：'.$this->order['content'].'<BR>';
                                $str .= '<BR>';
                                $str .= '<PLUGIN>';
                                $str .= '<BR>';
                                if ($total > 0)
                                    $html .= $str;
                                $num++;
                            }
                        }else{
                            //全部商品一单
                            $total = 0;
                            $str = '';
                            $str .= '<CB>'.$this->name.'</CB><BR>';
                            $str .= '<C>'.$this->value['name'].'</C><BR>';  //帐单名称
                            /*$str .= '<CB>排队号：'.$this->getSerialNumber($this->result['serialNumber']).'</CB><BR>';*/
                            $str .= '订单号：'.$this->order['orderNO'].'<BR>';
                            $str .= '时间：'.date('Y-m-d H:i').'<BR>';
                            /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';
                            $str .= '操作人：'.$this->model->operator.'<BR>';*/
                            $str .= '--------------------------------<BR>';
                            $str .= '名称　　　　　             数量<BR>';
                            $str .= '--------------------------------<BR>';
                            foreach ($this->goodsData as $goods)
                            {
                                if (empty($type) || in_array($goods['categoryId'], $type))
                                {
                                    $name = BaseHelper::printCaiName($goods['name'],1);
                                    $str .= $name .'   '. '<B>'.$goods['quantity'] . '份</B>  <BR>';
                                    $total += $goods['price'] * $goods['quantity'];
                                }
                            }
                            $str .= '--------------------------------<BR>';
                            $str .= '备注：'.$this->order['content'].'<BR>';
                            $str .= '<BR>';
                            $str .= '<PLUGIN>';
                            $str .= '<BR>';
                            if ($total > 0)
                                $html .= $str;
                        }
                    }elseif ($this->value['name'] == '结帐单'){
                        $total = 0;
                        $str = '';
                        $str .= '<CB>'.$this->name.'</CB><BR>';
                        $str .= '<C>'.$this->value['name'].'</C><BR>';  //帐单名称
                        $str .= '订单号：'.$this->order['orderNO'].'<BR>';
                        $str .= '时间：'.date('Y-m-d H:i').'<BR>';
                        /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';
                        $str .= '操作人：'.$this->model->operator.'<BR>';*/
                        $str .= '--------------------------------<BR>';
                        $str .= '名称　　　　　  单价  数量 金额<BR>';
                        $str .= '--------------------------------<BR>';
                        foreach ($this->goodsData as $goods)
                        {
                            $len = strlen($goods['name'])/3*2;  //12
                            $str .= $goods['name'].str_pad('',14 - $len,' ').' '.str_pad($goods['price']/100, 5, ' ').'   '.$goods['quantity'].'  '.sprintf('%.2f', $goods['price']/100 * $goods['quantity']).'<BR>';
                            $total += $goods['price'] * $goods['quantity'];
                        }
                        $str .= '--------------------------------<BR>';
                        $str .= '合计：'. str_pad(sprintf('%.2f', $total/100), 24, ' ', STR_PAD_LEFT).'<BR>';
                        $discount = ($this->order['oldSaleMoney'] + $this->order['oldMemberPrice'])/100;
                        $str .= '运费：'. str_pad(sprintf('%.2f', $this->order['freight']/100), 24, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '包装费：'. str_pad(sprintf('%.2f', $this->order['packingfee']/100), 22, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '应付：'. str_pad(sprintf('%.2f', $this->order['total']/100 + $discount), 24, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '优惠：'. str_pad(sprintf('%.2f', $discount/100), 24, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '--------------------------------<BR>';
                        $str .= '实付：'. str_pad(sprintf('%.2f', $this->order['total']/100), 24, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '找零：'. str_pad(0.00, 24, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '交易时间：'.date('Y-m-d H:i').'<BR>';
                        $str .= '--------------------------------<BR>';
                        $str .= '备注：'.$this->order['content'].'<BR>';
                        $str .= '<BR>';
                        /*$str .= '<C>提前扫码关注，优惠买单</C><BR>';
                        $str .= '<QR>http://www.1miaodao.cn</QR>';*/
                        $str .= '<PLUGIN>';
                        $str .= '<BR>';
                        $html .= $str;
                    }
                }


            }elseif ($this->printtype == 2){
                //80mm打印机
                if(isset($this->value['isdadaprint']) && $this->value['isdadaprint'] == 'yes'){
                    //达达配送单
                    $total = 0;
                    $str = '';
                    $str .= '<CB>'.$this->name.'</CB><BR>';
                    $str .= '<C>'.$this->value['xiaopiaoname'].'</C><BR>';  //帐单名称
                    if($this->order['status'] != 1){
                        $str .= '<CB>（已支付）</CB><BR>';
                    }else{
                        $str .= '<CB>（未支付）</CB><BR>';
                    }
                    $str .= '订单号：'.$this->order['orderNO'].'<BR>';
                    $str .= '支付时间：'.$this->order['payDate'].'<BR>';
                    /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';
                    $str .= '操作人：'.$this->model->operator.'<BR>';*/
                    $str .= '-----------------------------------------------<BR>';
                    $str .= '名称　　　　　       单价      数量      金额<BR>';
                    $str .= '-----------------------------------------------<BR>';
                    foreach ($this->goodsData as $goods)
                    {
                        $len = strlen($goods['name'])/3*2;  //12
                        $str .= $goods['name'].str_pad('',14 - $len,' ').'     '.str_pad($goods['price']/100, 5, ' ').'        '.$goods['quantity'].'       '.sprintf('%.2f', $goods['price']/100 * $goods['quantity']).'<BR>';
                        $total += $goods['price'] * $goods['quantity'];
                    }
                    $str .= '-----------------------------------------------<BR>';
                    $discount = ($this->order['oldSaleMoney'] + $this->order['oldMemberPrice'])/100;
                    $str .= '配送费：'. str_pad(sprintf('%.2f', $this->order['freight']/100), 36, ' ', STR_PAD_LEFT).'<BR>';
                    $str .= '包装费：'. str_pad(sprintf('%.2f', $this->order['packingfee']/100), 36, ' ', STR_PAD_LEFT).'<BR>';
                    $str .= '-----------------------------------------------<BR>';
                    $str .= '原价：'. str_pad(sprintf('%.2f', $this->order['total']/100 + $discount), 38, ' ', STR_PAD_LEFT).'<BR>';
                    $str .= '优惠：'. str_pad(sprintf('%.2f', $discount), 38, ' ', STR_PAD_LEFT).'<BR>';
                    $str .= '实付：'. str_pad(sprintf('%.2f', $this->order['total']/100), 38, ' ', STR_PAD_LEFT).'<BR>';
                    $str .= '-----------------------------------------------<BR>';
                    $str .= '<BR>';
                    $str .= '<B>地址：'.$this->order['deliverAddress'].'</B><BR><BR>';
                    $str .= '<B>'.$this->order['userPhone'].'</B><BR>';
                    $str .= '-----------------------------------------------<BR>';
                    $str .= '备注：'.$this->order['content'].'<BR>';
                    $str .= '<BR>';
                    //$str .= '<C>扫一扫提前线上点餐，优惠买单</C><BR>';
                    $str .= '<PLUGIN>';
                    $str .= '<BR>';
                    $html .= $str;
                }else{
                    if ($this->value['name'] == '对帐单'){
                        if ($this->value['mode'] == '一个商品一单'){
                            foreach ($this->goodsData as $goods){
                                if (empty($type) || in_array($goods['categoryId'], $type))
                                {
                                    $total = 0;
                                    $str = '';
                                    if ($total > 0)
                                        $str .= '<CUT>';
                                    $str .= '<CB>'.$this->name.'</CB><BR>';
                                    $str .= '<C>'.$this->value['name'].'</C><BR>';  //帐单名称
                                    /*$str .= '<CB>排队号：'.$this->getSerialNumber($this->result['serialNumber']).'</CB><BR>';*/
                                    $str .= '订单号：' . $this->order['orderNO'] . '<BR>';
                                    $str .= '时间：'.date('Y-m-d H:i').'<BR>';
                                    /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';
                                    $str .= '操作人：'.$this->model->operator.'<BR>';*/
                                    $str .= '-----------------------------------------------<BR>';
                                    $str .= '名称　　　　　       单价       数量     金额<BR>';
                                    $str .= '-----------------------------------------------<BR>';

                                    $len = strlen($goods['name'])/3*2;  //12
                                    $str .= $goods['name'].str_pad('',14 - $len,' ').' '.str_pad($goods['price'], 5, ' ').'   '.$goods['quantity'].'  '.sprintf('%.2f', $goods['price'] * $goods['quantity']).'<BR>';
                                    $total += $goods['price'] * $goods['quantity'];

                                    $str .= '-----------------------------------------------<BR>';
                                    $str .= '合计：'. str_pad(sprintf('%.2f', $total), 38, ' ', STR_PAD_LEFT).'<BR>';
                                    $str .= '-----------------------------------------------<BR>';
                                    $str .= '备注：'.$this->order['content'].'<BR>';
                                    $str .= '<BR>';
                                    $str .= '<C>扫一扫提前线上点餐，优惠买单</C><BR>';
                                    $str .= '<PLUGIN>';
                                    $str .= '<BR>';
                                    $html .= $str;
                                }
                            }
                        }else{
                            $total = 0;
                            $str = '';
                            $str .= '<CB>'.$this->name.'</CB><BR>';
                            $str .= '<C>'.$this->value['name'].'</C><BR>';  //帐单名称
                            /*$str .= '<CB>排队号：'.$this->getSerialNumber($this->result['serialNumber']).'</CB><BR>';*/
                            $str .= '订单号：' . $this->order['orderNO'] . '<BR>';
                            $str .= '时间：'.date('Y-m-d H:i').'<BR>';
                            /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';
                            $str .= '操作人：'.$this->model->operator.'<BR>';*/
                            $str .= '-----------------------------------------------<BR>';
                            $str .= '名称　　　　　       单价       数量     金额<BR>';
                            $str .= '-----------------------------------------------<BR>';
                            foreach ($this->goodsData as $goods)
                            {
                                if (empty($type) || in_array($goods['categoryId'], $type))
                                {
                                    $len = strlen($goods['name']) / 3 * 2;  //12
                                    $str .= $goods['name'].str_pad('',14 - $len,' ').'     '.str_pad($goods['price'], 5, ' ').'        '.$goods['quantity'].'       '.sprintf('%.2f', $goods['price'] * $goods['quantity']).'<BR>';
                                    $total += $goods['price'] * $goods['quantity'];
                                }
                            }
                            $str .= '-----------------------------------------------<BR>';
                            $str .= '合计：'. str_pad(sprintf('%.2f', $total), 38, ' ', STR_PAD_LEFT).'<BR>';
                            $str .= '-----------------------------------------------<BR>';
                            $str .= '备注：'.$this->order['content'].'<BR>';
                            $str .= '<BR>';
                            $str .= '<C>扫一扫提前线上点餐，优惠买单</C><BR>';
                            $str .= '<PLUGIN>';
                            $str .= '<BR>';
                            if ($total > 0)
                                $html .= $str;
                        }
                    }elseif ($this->value['name'] == '出品单'){
                        if ($this->value['mode'] == '一个商品一单'){
                            $num = 0;
                            foreach ($this->goodsData as $goods)
                            {
                                if (empty($type) || in_array($goods['categoryId'], $type))
                                {
                                    $str = '';
                                    if ($num > 0)
                                        $str .= '<CUT>';
                                    $str .= '<CB>' . $this->name . '</CB><BR>';
                                    $str .= '<C>' . $this->value['name'] . '</C><BR>';  //帐单名称
                                    /*$str .= '<CB>排队号：'.$this->getSerialNumber($this->result['serialNumber']).'</CB><BR>';*/
                                    $str .= '订单号：' . $this->order['orderNO'] . '<BR>';
                                    $str .= '时间：' . date('Y-m-d H:i') . '<BR>';
                                    /*$str .= '餐桌：' . $this->result['tableName'] . '　　　　　 人数：' . $this->result['number'] . '<BR>';
                                    $str .= '操作人：'.$this->model->operator.'<BR>';*/
                                    $str .= '-----------------------------------------------<BR>';
                                    $str .= '名称　　　　　                          数量  <BR>';
                                    $str .= '-----------------------------------------------<BR>';
                                    $name = BaseHelper::printCaiName($goods['name'],2);
                                    $str .= $name.'    '.'<B>' . $goods['quantity'] . '份</B>'.'  <BR>';
                                    $str .= '-----------------------------------------------<BR>';
                                    $str .= '备注：' . $this->order['content'] . '<BR>';
                                    $str .= '<BR>';
                                    $str .= '<BR>';
                                    $str .= '<PLUGIN>';
                                    $str .= '<BR>';
                                    $html .= $str;
                                    $num++;
                                }
                            }
                        }elseif ($this->value['mode'] == '分类打印'){
                            $num = 0;
                            $newgoodsData = array();
                            foreach ($this->goodsData as $k=>$v){
                                $newgoodsData[$v['caiping']][] = $v;
                            }
                            foreach ($newgoodsData as $k=>$goods){
                                $total = 0;
                                $str = '';
                                if($num>0)
                                    $str .= '<CUT>';
                                $str .= '<CB>'.$this->name.'</CB><BR>';
                                $str .= '<C>'.$this->value['name'].'</C><BR>';  //帐单名称
                                /*$str .= '<CB>排队号：'.$this->getSerialNumber($this->result['serialNumber']).'</CB><BR>';*/
                                $str .= '订单号：'.$this->order['orderNO'].'<BR>';
                                $str .= '时间：'.date('Y-m-d H:i').'<BR>';
                                /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';
                                $str .= '操作人：'.$this->model->operator.'<BR>';*/
                                $str .= '<B>品类：'.$k.'</B><BR>';
                                $str .= '-----------------------------------------------<BR>';
                                $str .= '名称　　　　　                          数量  <BR>';
                                $str .= '-----------------------------------------------<BR>';
                                foreach ($goods as $good){
                                    if (empty($type) || in_array($good['categoryId'], $type))
                                    {
                                        $name = BaseHelper::printCaiName($good['name'],2);
                                        $str .= $name.'    '.'<B>' . $good['quantity'] . '份</B>'.'  <BR>';
                                        $total += $good['price'] * $good['quantity'];
                                    }
                                }

                                $str .= '-----------------------------------------------<BR>';
                                $str .= '备注：'.$this->order['content'].'<BR>';
                                $str .= '<BR>';
                                $str .= '<PLUGIN>';
                                $str .= '<BR>';
                                if ($total > 0)
                                    $html .= $str;
                                $num++;

                            }
                        }else{
                            //全部商品一单
                            $total = 0;
                            $str = '';
                            $str .= '<CB>'.$this->name.'</CB><BR>';
                            $str .= '<C>'.$this->value['name'].'</C><BR>';  //帐单名称
                            /*$str .= '<CB>排队号：'.$this->getSerialNumber($this->result['serialNumber']).'</CB><BR>';*/
                            $str .= '订单号：'.$this->order['orderNO'].'<BR>';
                            $str .= '时间：'.date('Y-m-d H:i').'<BR>';
                            /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';
                            $str .= '操作人：'.$this->model->operator.'<BR>';*/
                            $str .= '-----------------------------------------------<BR>';
                            $str .= '名称　　　　　                          数量  <BR>';
                            $str .= '-----------------------------------------------<BR>';
                            foreach ($this->goodsData as $goods)
                            {
                                if (empty($type) || in_array($goods['categoryId'], $type))
                                {
                                    $name = BaseHelper::printCaiName($goods['name'],2);
                                    $str .= $name.'    '.'<B>' . $goods['quantity'] . '份</B>'.'  <BR>';
                                    $total += $goods['price'] * $goods['quantity'];
                                }
                            }
                            $str .= '-----------------------------------------------<BR>';
                            $str .= '备注：'.$this->order['content'].'<BR>';
                            $str .= '<BR>';
                            $str .= '<PLUGIN>';
                            $str .= '<BR>';
                            if ($total > 0)
                                $html .= $str;

                        }
                    }elseif ($this->value['name'] == '结帐单'){
                        $total = 0;
                        $str = '';
                        $str .= '<CB>'.$this->name.'</CB><BR>';
                        $str .= '<C>'.$this->value['name'].'</C><BR>';  //帐单名称
                        $str .= '订单号：'.$this->order['orderNO'].'<BR>';
                        $str .= '时间：'.date('Y-m-d H:i').'<BR>';
                        /*$str .= '餐桌：'.$this->result['tableName'].'　　　　　 人数：'.$this->result['number'].'<BR>';
                        $str .= '操作人：'.$this->model->operator.'<BR>';*/
                        $str .= '-----------------------------------------------<BR>';
                        $str .= '名称　　　　　       单价      数量      金额<BR>';
                        $str .= '-----------------------------------------------<BR>';
                        foreach ($this->goodsData as $goods)
                        {
                            $len = strlen($goods['name'])/3*2;  //12
                            $str .= $goods['name'].str_pad('',14 - $len,' ').'     '.str_pad($goods['price']/100, 5, ' ').'        '.$goods['quantity'].'       '.sprintf('%.2f', $goods['price']/100 * $goods['quantity']).'<BR>';
                            $total += $goods['price'] * $goods['quantity'];
                        }
                        $str .= '-----------------------------------------------<BR>';
                        $str .= '合计：'. str_pad(sprintf('%.2f', $total/100), 38, ' ', STR_PAD_LEFT).'<BR>';
                        $discount = ($this->order['oldSaleMoney'] + $this->order['oldMemberPrice'])/100;
                        $str .= '运费：'. str_pad(sprintf('%.2f', $this->order['freight']/100), 38, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '包装费：'. str_pad(sprintf('%.2f', $this->order['packingfee']/100), 36, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '应付：'. str_pad(sprintf('%.2f', $this->order['total']/100 + $discount), 38, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '优惠：'. str_pad(sprintf('%.2f', $discount), 38, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '-----------------------------------------------<BR>';
                        $str .= '实付：'. str_pad(sprintf('%.2f', $this->order['total']/100), 38, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '找零：'. str_pad(0.00, 38, ' ', STR_PAD_LEFT).'<BR>';
                        $str .= '交易时间：'.date('Y-m-d H:i').'<BR>';
                        $str .= '-----------------------------------------------<BR>';
                        $str .= '备注：'.$this->order['content'].'<BR>';
                        $str .= '<BR>';
                        $str .= '<C>扫一扫提前线上点餐，优惠买单</C><BR>';
                        $str .= '<PLUGIN>';
                        $str .= '<BR>';
                        $html .= $str;
                    }
                }

            }
        }

        return $html;
    }
}